package com.aop.demo.web;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.aop.demo.annotation.LogAnnotation;
import com.aop.demo.annotation.PermissionAnnotation;
import com.aop.demo.enums.LogicalEnum;
import com.aop.demo.response.ResultCode;
import com.aop.demo.response.ResultObj;

@RestController
@RequestMapping("/permission")
public class PermissionController {

	@RequestMapping("pagePermission")
	@LogAnnotation()
	public String pagePermission() {
		
		return "";
	}
	
	@GetMapping("havePermission")
	@PermissionAnnotation(value = ("ldq"))
	@LogAnnotation(desc = ("有权限验证"))
	public ResultObj<String> havePermission(Long id, String value) {
		
        return ResultObj.success("成功返回数据");
	}
	
	@GetMapping("defauleAndPermission")
	@PermissionAnnotation(value = ("ldq"))//等于 @LogAnnotation(desc = ("默认AND权限验证"), LogicalEnum.AND)
	@LogAnnotation(desc = ("默认AND权限验证"))
	public ResultObj<String> defauleAndPermission(Long id, String value) {
		
        return ResultObj.success("成功返回数据");
	}
	
	@GetMapping("multiAndPermission")
	@PermissionAnnotation(value = {"admin", "ldq"}, logical = LogicalEnum.AND)
	@LogAnnotation(desc = ("多个权限同时满足"))
	public ResultObj<String> multiAndPermission(Long id, String value) {
		
        return ResultObj.success("成功返回数据");
	}
	
	@GetMapping("multiOrPermission")
	@PermissionAnnotation(value = {"test", "ldq"}, logical = LogicalEnum.OR)
	@LogAnnotation(desc = ("多个权限满足一个"))
	public ResultObj<String> multiOrPermission(Long id, String value) {
		
        return ResultObj.success("成功返回数据");
	}
	
	@GetMapping("noPermission")
	@PermissionAnnotation(value = {"no", "page"}, logical = LogicalEnum.AND)
	@LogAnnotation(desc = ("没有权限测试"))
	public ResultObj<String> noPermission() {
		
        return ResultObj.failure(ResultCode.PERMISSION_NO_ACCESS);
	}
}
